<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>项目转办组织架构设置表 管理</title>
    <style type="text/css">
    </style>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <table class="layout2col1">
            <tbody>
            <tr>
                <td width="50%" valign="top">
                    <div class="sqPanel">
                        <div class="sqPanel_head">
                            <span><i class="sqIco sqIco_3"></i>转出组织架构</span>
                        </div>
                        <div class="sqPanel_head">
                            <form id="outOrgForm" class="titSearchBar">
                                <div class="fieldset1 clearFix">
                                    <div class="fieldBox">
                                        <div class="label">资源名称</div>
                                        <div class="field">
                                            <input name="outOrgNm" id="outOrgNm" type="text" class="ui-textbox" value=""
                                                   ligerui="width: 100">
                                        </div>
                                    </div>
                                    <span id="outOrgSearchBtn" class="sq-search-button"></i>查询</span>
                                </div>
                            </form>
                        </div>
                        <div class="sqPanel_body" style="min-height: 300px;">
                            <ul id="tree1">
                            </ul>
                        </div>
                    </div>
                </td>
                <td width="50%" valign="top">
                    <div class="sqPanel">
                        <div class="sqPanel_head">
                            <span><i class="sqIco sqIco_3"></i>转入组织架构</span>
                        </div>
                        <div class="sqPanel_head">
                            <form id="inOrgForm" class="titSearchBar">
                                <div class="fieldset1 clearFix">
                                    <div class="fieldBox">
                                        <div class="label">资源名称</div>
                                        <div class="field">
                                            <input name="inOrgNm" id="inOrgNm" type="text" class="ui-textbox" value=""
                                                   ligerui="width: 100">
                                        </div>
                                    </div>
                                    <span id="inOrgSearchBtn" class="sq-search-button"></i>查询</span>
                                    <span id="authoBtn" class="sq-search-button"></i>授权</span>
                                </div>
                            </form>
                        </div>
                        <div class="sqPanel_body" style="min-height: 300px;">
                            <ul id="tree2">
                            </ul>
                        </div>
                    </div>
                </td>
            </tr>
            </tbody>
        </table>
    </div>
    <div id="ligergrid1" class="sq-grid"></div>
</div>

<script type="text/javascript">
    var tree,
        tree2,
        inOrgArr = [];
    $(function () {
        /* 转出树的构建开始 */
        tree = $("#tree1").ligerTree({
            url: '<%=path%>/project/prjTransSetting/initOrgList.do',
            ajaxType: 'get',
            checkbox: false,
            parentIcon: "SqFolder",
            childIcon: "SqLeaf",
            needCancel: false,
            isExpand: true,
            onContextmenu: function (node, e) {
                actionNode = node;
                var parentNode = tree.getParent(node);
                if (parentNode) {
                    treeMenu.hide();
                    treeMenu2.show({top: e.pageY, left: e.pageX});
                } else {  //没有父节点，那就是根节点
                    treeMenu2.hide();
                    treeMenu.show({top: e.pageY, left: e.pageX});
                }
                ;
                return false;
            },
            onSelect: function () {
                var tree2Checked = tree2.getChecked();
                $.each(tree2Checked,function (i,o) {
                    tree2.cancelSelect(tree2Checked[i]);
                });
                var outOrgData = tree.getSelected().data;
                var outOrgId = outOrgData.id;
                $.ajax({
                    url: '<%=path%>/project/prjTransSetting/getCheckedOrgByOutOrgId.do?outOrgId=' + outOrgId,
                    type: 'GET',
                    dataType: 'json',
                    success: function (result) {
                        var sysOrgArr = result.data.data;
                        $.each(sysOrgArr,function (i,o) {
                            tree2.selectNode(sysOrgArr[i].id);
                        });
                    }
                });
            },
            onCancelselect: function (data, target) {
                $("#sysOrg_form").addClass('Hide');
                $("#sysOrg_form_t").removeClass('Hide');
            },
            onSuccess: function (data) {
                // tree.selectNode(data[0]);
            }
        });

        /* 转入树的构建开始 */
        tree2 = $("#tree2").ligerTree({
            url: '<%=path%>/project/prjTransSetting/initOrgList.do',
            ajaxType: 'get',
            nodeWidth: 300,
            parentIcon: "SqFolder",
            childIcon: "SqLeaf",
            autoCheckboxEven: true,
            iconClsFieldName: "iconClass",
            enabledCompleteCheckbox: false,
            onCheck: function (item, checked) {
                if (!tree.getSelected()) {
                    top.$.ligerDialog.SQalert({content: LogUtils.LOG_PRJ_TRANS_OUTORG_REQUIRED, SQ_type: "warning"});
                    tree2.cancelSelect(item);
                    return;
                }
                ;
                //var checkNodes=getCheckNodes(item.data);
                //setRESOURCE_IDs(checkNodes, checked);
                // SQ.setIDs_onCheckTree(item, checked, tree, RESOURCE_IDs);
                //alert(RESOURCE_IDs);
            },
            onSuccess: function (data) {
                setNanoScroller();
            }
        });

        function setNanoScroller() {
            $(".nanoWrap .nano").nanoScroller({
                preventPageScrolling: true
            });
        }

        /* 转入树的构建结束 */

        $("#reloadTree_btn").click(function (event) {
            tree.reload();
        });

        var idEdit;

        function changeForm() {
            $("#sysOrg_form_t").addClass('Hide');
            $("#sysOrg_form").removeClass('Hide');
            setForm();

        }

        function detailForm() {
            $("#sysOrg_form").addClass('Hide');
            $("#sysOrg_form_t").removeClass('Hide');
        }

        function onSelectTree(node) {
            $("#saveNew_btn").addClass("Hide");
            $("#change_btn").removeClass("Hide");
            //console.log(node.data);
            //alert(JSON.stringify(node));
            detailForm()

            $.ajax({
                type: 'get',
                dataType: 'json',
                data: {id: node.data.id},
                url: '<%=path%>/project/prjTransSetting/getOrgById.do',
                success: function (msg) {
                    if (msg.success == 1) {
                        setValueToText(msg.data);
                        idEdit = msg.data.id;
                        isEditable(msg.data.isSysDef);

                    } else {

                    }
                }
            });
        }

        /*
            是否系统内置参数获取
        */
        function isEditable(isSysDef) {
            if (isSysDef == 0) {
                Editable = true;
            } else {
                Editable = false;
            }
        }

        function setForm() {
            $("#sysOrg_form").ligerForm({
                validate: true
            });
        }

        //赋值方法到详细
        function setValueToText(data) {
            $("#orgNm_txt").text(isNulltoNBSP(data.orgNm));
            $("#orgShtNm_txt").text(isNulltoNBSP(data.orgShtNm));
            $("#orgDispNm_txt").text(isNulltoNBSP(data.orgDispNm));
            $("#orgCd_txt").text(isNulltoNBSP(data.orgCd));
            $("#sortNo_txt").text(isNulltoNBSP(data.sortNo));
            $("#parOrgDispNm_txt").text(isNulltoNBSP(data.pidNm));
            $("#orgTypCd_text").text(isNulltoNBSP(data.orgTypCdNm));
            $("#orgRem_txt").text(isNulltoNBSP(data.orgRem));
        }

        function isNulltoNBSP(a) {
            if (a == null || a == undefined) {
                return ""
            } else {
                return a;
            }
        }

        // grid.setHeight(100);

        $("#searchBar").ligerForm();
        /* 转出树的构建结束 */

        // 点击左边转出组织架构重置右边的树
        function resetResource() {

        }

        $("#authoBtn").click(function () {
            if (!tree.getSelected()) {
                top.$.ligerDialog.SQalert({content: LogUtils.LOG_PRJ_TRANS_OUTORG_REQUIRED, SQ_type: "warning"});
                return;
            }
            ;
            if (!tree2.getChecked()) {
                top.$.ligerDialog.SQalert({content: LogUtils.LOG_PRJ_TRANS_INORG_REQUIRED, SQ_type: "warning"});
                return;
            }
            ;

            // 转出机构参数
            var outOrgData = tree.getSelected().data;
            var outOrgId = outOrgData.id;
            var outOrgCd = outOrgData.orgCd;
            var outOrgNm = outOrgData.orgDispNm;

            // 转入机构参数
            inOrgArr = tree2.getCheckedData();

            $.ajax({
                url: '<%=path%>/project/prjTransSetting/add.do',
                type: 'post',
                dataType: 'json',
                data: {
                    'outOrgId': outOrgId,
                    'outOrgCd': outOrgCd,
                    'outOrgNm': outOrgNm,
                    'inOrgArr[]': JSON.stringify(inOrgArr)
                },
                success: function (msg) {
                    if (msg.success == 1) {
                        top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                    } else {
                        top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                    }
                }
            });
            //ligerDialogSuc("授权成功！",1000)
        });
        // 转出组织架构查询按钮
        $("#outOrgSearchBtn").click(function () {
            // var form = liger.get("outOrgForm");
            var outOrgNm = $("#outOrgNm")
            // $.extend(true, outOrgNm);
            //alert(JSON.stringify(data));
            $.ajax({
                url: '<%=path%>/project/prjTransSetting/getByResNm.do',
                type: 'GET',
                dataType: 'json',
                data: outOrgNm,
                success: function (result) {
                    tree.setData(result.data[0].children);
                }
            });
        });
        // 转入组织架构查询按钮
        $("#inOrgSearchBtn").click(function () {
            // var form = liger.get("outOrgForm");
            var inOrgNm = $("#inOrgNm")
            // $.extend(true, outOrgNm);
            //alert(JSON.stringify(data));
            $.ajax({
                url: '<%=path%>/project/prjTransSetting/getByResNm.do',
                type: 'GET',
                dataType: 'json',
                data: inOrgNm,
                success: function (result) {
                    tree2.setData(result.data[0].children);
                }
            });
        });

    });

</script>

</body>
</html>
